home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / PROTECTO / PMCOMMON.C next >
Text File  |  1991-10-07  |  1KB  |  64 lines

  1. /*
  2.  * pmCommon.h - appleshare dump/load protections common code
  3.  * by Aaron Wohl (aw0g+@andrew.cmu.edu)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include "pmCommon.h"
  11.  
  12. cache_entry none_cache={"\p*none*",0};
  13.  
  14. void allocate_cache_entries()
  15. {
  16.     group_cache=(cache_entry_pt)NewPtr(CACHE_SIZE*sizeof(*group_cache));
  17.     user_cache=(cache_entry_pt)NewPtr(CACHE_SIZE*sizeof(*group_cache));
  18.     if((group_cache==0)||
  19.        (user_cache==0)) {
  20.          printf("fatal:not enough memory to allocate user and group caches");
  21.          exit(1);
  22.     }
  23.     memset(group_cache,0,CACHE_SIZE*sizeof(*group_cache));
  24.     memset(user_cache,0,CACHE_SIZE*sizeof(*user_cache));
  25.     *group_cache = none_cache;
  26.     *user_cache = none_cache;
  27. }
  28.  
  29. /*
  30.  * read a line from a file
  31.  */
  32. int read_line(char *aline,FILE *afile)
  33. {
  34.     char *s;
  35.     if(fgets(aline,ERR_BUF_SIZE-10,afile)!=aline)
  36.         return TRUE;
  37.     aline[ERR_BUF_SIZE-10]=0;
  38.     if((s=strchr(aline,'\n'))!=0)
  39.         *s=0;
  40.     return FALSE;
  41. }
  42.  
  43. /*
  44.  * get volume id of a volume
  45.  * returns -1 on an error
  46.  */
  47. long get_vol_id(char *in_name)
  48. {
  49.     int os;
  50.     HParamBlockRec vinfo;
  51.     char aname[300];
  52.     memset(&vinfo,0,sizeof(vinfo));
  53.     strcpy(aname+1,in_name);
  54.     strcat(aname+1,":");
  55.     aname[0]=strlen(aname+1);
  56.     vinfo.volumeParam.ioNamePtr=(StringPtr)aname;
  57.     vinfo.volumeParam.ioVRefNum= 0;
  58.     vinfo.volumeParam.ioVolIndex= -1;
  59.     os=PBHGetVInfo(&vinfo,FALSE);
  60.     if(os!=0) 
  61.         return BAD_VOL_NUM;
  62.     return vinfo.volumeParam.ioVRefNum;
  63. }
  64.